package com.easybuilder.common.utils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class NetUtil {

    public static boolean ping(String ip) {
        try (InputStream ins = Runtime.getRuntime().exec("ping " + ip).getInputStream();
             BufferedReader br = new BufferedReader(new InputStreamReader(ins, "GBK"));){
            String len = "";
            while ((len = br.readLine())  != null) {
                if (len.equals("TTL")) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
